package Control_Layer;

import Model_Layer.*;
import DB_Layer.*;

import java.util.ArrayList;

/***
 * PersonCTR.java
 * UCN dmaa0214 - October 2014 
 * 
 * @author Group 5 
 * @version 1.0
 * 
 */
public class PersonCTR {
	
	// creates new instance of PersonCTR
	public PersonCTR() {
		
	}
	
	/* Customer Methods */		
	
	public void createCustomer(int cusID, String name, String address, String email,
			String zipCode, String phoneNo, String country, 
			String discount, char private_Business) {
		
		Customer cusObj = new Customer();
		Zipcode_City zipcode_cityObj = new Zipcode_City();
		
		// set up new customer object
		// id will be set in db class
		cusObj.setCusID(0);
		cusObj.setName(name);
		cusObj.setAddress(address);
		cusObj.setEmail(email);
		cusObj.setZipCode(zipcode_cityObj);
		cusObj.setPhoneNo(phoneNo);
		cusObj.setCountry(country);
		cusObj.setDiscount(discount);
		cusObj.setPrivate_Business(private_Business);
		
		try {
			DbConnection.startTransaction();
			DB_Customer dbCus = new DB_Customer();
			dbCus.insertCustomer(cusObj);
			DbConnection.commitTransaction();
		}
		catch(Exception e) {
			DbConnection.rollbackTransaction();
		}	
	}

	public void updateCustomer(String name, String address, String email,
		Zipcode_City zipCode, String phoneNo, String country, 
			String discount, char private_Business) {
		
		IFDB_Customer dbCus = new DB_Customer();		
		Customer cus = new Customer();
		
		// update customer
		cus.setName(name);
		cus.setAddress(address);
		cus.setEmail(email);
		cus.setZipCode(zipCode);
		cus.setPhoneNo(phoneNo);
		cus.setCountry(country);
		cus.setDiscount(discount);
		cus.setPrivate_Business(private_Business);
		
		dbCus.updateCustomer(cus);
	}
	
	//??
	public void deleteCustomer(int cusID, String name) {
		
		IFDB_Customer dbSup = new DB_Customer();
		dbSup.deleteCustomer(name);
	}

	public Customer getCustomer(String name) {
		
		IFDB_Customer dbCus = new DB_Customer();
		return dbCus.getCustomer(name);
	}
	

	public ArrayList<Customer> getAllCustomers() {
		
		IFDB_Customer dbCus = new DB_Customer();
		ArrayList<Customer> allCus = new ArrayList<Customer>();
		allCus = dbCus.getAllCustomers();
		return allCus;
	}

	
	
	
	/* Supplier Methods */	
	public void createSupplier(int cusID, String name, String address, String email, Zipcode_City zipCode,
			String phoneNo, String country) {
		
		Supplier supObj = new Supplier();
		
		// set up new Supplier object
		supObj.setSupID(0);
		supObj.setName(name);
		supObj.setAddress(address);
		supObj.setEmail(email);
		supObj.setZipCode(zipCode);
		supObj.setPhoneNo(phoneNo);
		supObj.setCountry(country);
		
		try {
			DbConnection.startTransaction();
			DB_Supplier dbSup = new DB_Supplier();
			dbSup.insertSupplier(supObj);
			DbConnection.commitTransaction();
		}
		catch(Exception e) {
			DbConnection.rollbackTransaction();
		}	
	}

	public void updateSupplier(String name, String address, String email, Zipcode_City zipCode,
			String phoneNo, String city, String country) {
		
		IFDB_Supplier dbSup = new DB_Supplier();
		Supplier sup = new Supplier();
		
		// update supplier
		sup.setName(name);
		sup.setAddress(address);
		sup.setEmail(email);
		sup.setZipCode(zipCode);
		sup.setPhoneNo(phoneNo);
		sup.setCountry(country);
		
		dbSup.updateSupplier(sup);
	}
	
	
	public void deleteSupplier(String name) {
		
		IFDB_Supplier dbSup = new DB_Supplier();
		dbSup.deleteSupplier(name);
	}
	
	// gets specific supplier
	public Supplier getSupplier(String name) {
		
		IFDB_Supplier dbSup = new DB_Supplier();
		return dbSup.getSupplier(name, false);	
	}
	
	// make an arraylist of all suppliers and returns it
	public ArrayList<Supplier> getAllSuppliers() {
		
		IFDB_Supplier dbSup = new DB_Supplier();
		ArrayList<Supplier> allSup = new ArrayList<Supplier>();
		allSup = dbSup.getAllSuppliers();
		return allSup;
	}	

}
